import requests
from bs4 import BeautifulSoup


def main(input_dict):
    '''
    本函数接受一个字典,然后获取其中BV号,取得视频详细信息
    然后以一个字典的形式返回
    '''
    dict_enriched = input_dict
    url = f"https://www.bilibili.com/video/{input_dict['video']}"
    print(f'正在获取{url}的详细信息')
    r = requests.get(url)
    r.encoding = 'utf-8'
    html = r.text
    '''分析时使用的代码
    with open('170001.html', mode='w', encoding='utf-8') as file1:
        file1.write(str(html))
    '''
    soup = BeautifulSoup(html, 'html.parser')
    for i in ('author', 'description', 'keywords'):
        info = soup.find('meta', attrs={'name': i})  # 查找div
        content = info.get("content")
        input_dict[i] = content
    dict_enriched = input_dict
    return dict_enriched


if __name__ == "__main__":
    print(main({'video': 'av170001', 'name': 'ass'}))
